﻿using System;

using System.Data;
using System.Data.SqlClient;

namespace IFD2
{
    public partial class Bulletin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "bll_sys_get_bulletin";
            SqlParameter para = cmd.Parameters.AddWithValue("@lang", Session["LANG"].ToString());
            DataTable myTab = new DataTable();
            TinyDAL.Exec(ref cmd, ref myTab);
            if (myTab.Rows.Count > 0)
                litContent.Text = myTab.Rows[0][0].ToString();
            else
                litContent.Text = "";

            string buf;
            buf = TinyDAL.Get_DB_UTC_Time();
            if (buf != "")
                lblDbTime.Text = buf; //+ " UTC";
            else
                lblDbTime.Text = "Failed to retreive database time!";

            //lblLastLogon.Text = Convert.ToDateTime(Session["LAST_LOGON"].ToString()).ToString("yyyy-M-d HH:mm")+ " UTC";

            string ip,proxy;
            if (Context.Request.ServerVariables["HTTP_VIA"] != null) // using proxy
            {
                ip = Context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; // Return real client IP.
                proxy = Context.Request.ServerVariables["HTTP_VIA"];
            }
            else //not using proxy or can't get the Client IP
            {
                ip = Context.Request.ServerVariables["REMOTE_ADDR"]; //While it can't get the Client IP, it will return proxy IP(s).
                proxy = "";
            }
            lblIP.Text = ip;//当前信息不能用gridview中数据，可能同时在别处登录，只能实时检测！
            if(proxy != "")
                lblIP.Text=lblIP.Text+ " via " + proxy;

            //lblHostName.Text = Request.UserHostName;//Context.Request.ServerVariables["REMOTE_HOST"];
            lblAgentInfo.Text = Helpers.UserAgent.Parse(Request.UserAgent,true);//Context.Request.ServerVariables["HTTP_USER_AGENT"];

            if(GridView1.Rows.Count >= 2)
            {
                if(GridView1.Rows[0].Cells[1].Text!= GridView1.Rows[1].Cells[1].Text
                    || GridView1.Rows[0].Cells[3].Text != GridView1.Rows[1].Cells[3].Text)
                {
                    lblWarning.Visible = true;
                }
            }

            if (Request.QueryString["islogonshow"] == "1")
                hidIsLogonShow.Value = "1";
            else
                hidIsLogonShow.Value = "0";
        }

        protected void lbtnQuery_Click(object sender, EventArgs e)
        {
            GridView1.DataBind();
            Page_Load(sender, e);
        }
    }
}